
import os, sys
sys.path.append('E:/VC/assetserver') # the parent directory of the project

import subprocess

script = 'C:/VC/assetserver/assets/damn/transcoders/b-script-transcoderimage.py'
script = 'C:/VC/assetserver/tests/transcoders/b-script-transcoderimage.py'

def RunBlenderURI(anURI, scriptPath):
  b = os.environ["BLENDER"].replace('"', '')
  s, t = subprocess.Popen([b, "-b", anURI, '-P', scriptPath], stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
  return s, t
 
asset = 'C:/VC/assetserver/assets/damn/repo/house14.blend'
object = 'house014'
#asset = 'C:/VC/assetserver/assets/damn/repo/cube2.blend'
#object = 'Cube2-object'

#asset = 'C:/VC/assetserver/tests/transcoders/arrow02.blend'
#object = 'Cylinder'

#asset = 'C:/VC/assetserver/tests/transcoders/buckler10.blend'
#object = 'buckler10'

#asset = 'C:/VC/assetserver/assets/damn/repo/book.blend'
#object = 'Cube'
 

os.environ["BlenderImageTranscoder-sizex"] = 256
os.environ["BlenderImageTranscoder-sizey"] = 256


os.environ["BlenderImageTranscoder-cameraType"] = 'PERSP'
os.environ["BlenderImageTranscoder-cameraAngley"] = 0.0
os.environ["BlenderImageTranscoder-typeName"] = 'mesh'
os.environ["BlenderImageTranscoder-object"] = object
#os.environ["BlenderImageTranscoder-path"] = 'C:/VC/assetserver/tests/transcoders/test.jpg'
#os.environ["BlenderImageTranscoder-angley"] = 1.0

os.environ["BlenderImageTranscoder-path"] = 'C:/VC/assetserver/tests/transcoders/test-%d.jpg'
os.environ["BlenderImageTranscoder-anglesy"] = str([1.0, -1.0])

stdoutdata, stderrdata = RunBlenderURI(asset, script)
   

print(stdoutdata.decode("utf-8"), '\n' ,stderrdata.decode("utf-8"))
